import request from '../request.ts'

//获取
export const getRoleList = async  (search:Object) => {
    let r:any = await request({
        url: '/system/role/list',
        method: 'get',
        loading: true,
        data:search
    })
    return {
        data:r.rows,
        total:r.total
    }
}

//新增
export const addRole = async  (data:Object) => {
    let r:any = await request({
        url: '/system/role',
        method: 'post',
        loading: true,
        data:data
    })
    return r
}
//修改菜单资源 /system/menu
export const editRole = async  (data:Object) => {
    let r:any = await request({
        url: '/system/role',
        method: 'put',
        loading: true,
        data:data
    })
    return r
}
//删除
export const delRole = async  (id:Number) => {
    let r:any = await request({
        url: '/system/role/' + id,
        method: 'delete',
        loading: true
    })
    return r
}
//获取角色的资源权限
export const getRoleMenuTreeselect = async  (roleId) => {
    let r:any = await request({
        url: '/system/menu/roleMenuTreeselect/' + roleId,
        method: 'get',
        loading: true
    })
    return {
        menus:r.menus,
        checkedKeys:r.checkedKeys
    }
}
// 查询职位已授权用户列表
export const allocatedUserList2 = (query)=> {
    return request({
      url: '/system/post/authUser/allocatedList',
      method: 'get',
      data: query
    })
  }
  
  // 查询角色未授权用户列表
  export const unallocatedUserList2 = (query)=> {
    return request({
      url: '/system/post/authUser/unallocatedList',
      method: 'get',
      data: query
    })
  }
// 取消用户授权角色
export const authUserCancel2 = (data)=> {
    return request({
      url: '/system/post/authUser/cancel',
      method: 'put',
      data: data
    })
  }
  
  // 批量取消用户授权角色
  export const authUserCancelAll2 = (data)=> {
    let search = []
    Object.keys(data).map(item=>{
      search.push(`${item}=`+data[item])
    })
    return request({
      url: '/system/post/authUser/cancelAll?'+search.join('&'),
      method: 'put',
      data: data
    })
  }
  // 授权用户选择
  export const authUserSelectAll2 = (data)=> {
    let search = []
    Object.keys(data).map(item=>{
      search.push(`${item}=`+data[item])
    })
    return request({
      url: '/system/post/authUser/selectAll?'+search.join('&'),
      method: 'put',
      data: data
    })
  }